<template>
  <footer class="footer">
    <span class="todo-count"
      ><strong>{{ deleList }}</strong
      >剩余</span
    >
    <ul class="filters">
      <li>
        <a
          :class="{ selected: type === 'all' }"
          href="#/"
          @click.prevent="filter('all')"
          >全部</a
        >
      </li>
      <li>
        <a
          :class="{ selected: type === 'active' }"
          href="#/active"
          @click.prevent="filter('active')"
          >进行中</a
        >
      </li>
      <li>
        <a
          :class="{ selected: type === 'completed' }"
          href="#/completed"
          @click.prevent="filter('completed')"
          >已完成</a
        >
      </li>
    </ul>
    <button class="clear-completed" @click="cleardata" v-show="showBtn">
      清除已完成
    </button>
  </footer>
</template>
<script>
export default {

  // 为什么要把名字给todotooter
  name: 'TodoFooter',
  props: {
    deleList: {
      type: Number,
      required: true,
    },
    showBtn: {
      type: Boolean,
      required: true,
    },
    type: {
      type: String,
      required: true,
    },
  },

  methods: {
    cleardata() {
      this.$emit('cleardata')
    },
  // 修改父组件中的type
  filter(type) {
    this.$emit('filter', type)
  },
  },


  computed: {
    list() {
      switch (type) {
        case 'all':
          return this.list
        case 'active':
          return (this.list = this.list.filter((item) => item.isDone))
        default:
          return (this.list = this.list.filter((item) => !item.isDone))
      }
    },
  },
}
</script>
<style lang="less" scoped></style>
